package com.phonegap.gwt.fbconnect.client.impl;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
import com.google.gwt.user.client.Window;
import com.phonegap.gwt.camera.client.Camera;
import com.phonegap.gwt.camera.client.CameraCallback;
import com.phonegap.gwt.camera.client.CameraOptions;
import com.phonegap.gwt.camera.client.PictureSourceType;
import com.phonegap.gwt.childbrowser.client.ChildBrowser;
import com.phonegap.gwt.childbrowser.client.OnCloseCallback;
import com.phonegap.gwt.childbrowser.client.OnOpenExternalCallback;
import com.phonegap.gwt.fbconnect.*;
import com.phonegap.gwt.fbconnect.client.*;
public class FBConnectImpl {

	

	
	
	  public native FBConnect getFBConnect() /*-{	   		
		var fb =  $wnd.FBConnect.install();
 		return fb;
}-*/;
	  
	  
	  
	  public native void logout(FBConnect fbconnect,String client_id) /*-{		
		fbconnect.logout(client_id);


}-*/;
	  
	  
	  public native void connect(FBConnect fbconnect,String client_id,String redir_url,String display,String scope) /*-{
	 	fbconnect.connect(client_id,redir_url,display,scope);
}-*/;
	  
	  
	  public native void setOnConnectCallback(FBConnect fbconnect,
			  OnConnectCallback callback) /*-{
	  	fbconnect.onConnect =  function() {
      @com.phonegap.gwt.fbconnect.client.impl.FBConnectImpl::handleOnConnect(Lcom/phonegap/gwt/fbconnect/client/OnConnectCallback;) (callback);
    };
}-*/;
	  
	  protected static final void handleOnConnect(OnConnectCallback callback) {
		    UncaughtExceptionHandler ueh = GWT.getUncaughtExceptionHandler();
	      try {
	    	  callback.onFBConnected();
		      } catch (Throwable t) {
		        ueh.onUncaughtException(t);
		        
		      }
	  }


	  public native  String getAccessToken(FBConnect fbconnect)/*-{
 	return fbconnect.accessToken;
}-*/;

	  

}
